package com.example.ch19_1.controller;

import com.example.ch19_1.entity.MyUser;
import com.example.ch19_1.mapper.UserMapper;
import com.example.ch19_1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MyUserController {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserService userService;
    @GetMapping("/selectAllUsers")
    public List<MyUser> selectAllUsers(){
        return userMapper.selectList(null);
    }
    @PostMapping("/addAUser")
    public MyUser addAUser(MyUser mu){
        //实体类主键属性使用@TableId注解后，主键自动回填
        int result = userMapper.insert(mu);
        return mu;
    }
    @PutMapping("/updateAUser")
    public boolean updateAUser(MyUser mu){
        return userService.updateById(mu);
    }
    @DeleteMapping("/deleteAUser")
    public boolean  deleteAUser(MyUser mu){
        return userService.removeById(mu);
    }
    @GetMapping("/getOne")
    public MyUser getOne(int id){
        return userService.getById(id);
    }
}
